package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.ICategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.parsers.ReturnTypeParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2024-11-12
 */
@Tag(name = "分类品牌")
@RestController
@RequestMapping("/categoryBrand")
public class CategoryBrandController extends BaseController {
    @Autowired
    private ICategoryBrandService categoryBrandService;
    @Qualifier("genericReturnTypeParser")
    @Autowired
    private ReturnTypeParser genericReturnTypeParser;

    @Operation(summary = "查询分类品牌列表")
    @GetMapping("/list")
    public TableDataInfo list(){
        startPage();
        List<CategoryBrand> categoryBrandList = categoryBrandService.selectCategoryBrandList();
        return getDataTable(categoryBrandList);
    }

    @Operation(summary = "新增分类品牌")
    @PostMapping
    public AjaxResult add(
            @Parameter(description = "分类品牌")
            @RequestBody CategoryBrand categoryBrand){
        categoryBrand.setCreateBy(SecurityUtils.getUsername());
        return toAjax(categoryBrandService.insertCategoryBrand(categoryBrand));
    }

    @Operation(summary = "删除分类品牌")
    @DeleteMapping
    public AjaxResult remove(
            @Parameter(description = "分类品牌id列表")
            @PathVariable List<Long> ids){
        return toAjax(categoryBrandService.removeBatchByIds(ids));
    }

    @Operation(summary = "根据分类id获取品牌列表")
    @GetMapping("/brandList/{categoryId}")
    public AjaxResult selectBrandListByCategoryId(
            @Parameter(description = "分类id")
            @PathVariable Long categoryId) {
        return success(categoryBrandService.selectBrandListByCategoryId(categoryId));
    }
}
